import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
} from '@nestjs/common';
import { HouseTypesService } from './types.service';
import { createTypesDto, deleteTypesDto, updateTypesDto } from './types.dto';
import { Result } from '../../result/Result';

@Controller('/house/types')
export class HouseTypesController {
  constructor(private readonly houseTypes: HouseTypesService) {}
  @Post('')
  async createType(@Body() { name, desc }: createTypesDto) {
    const { count } = await this.houseTypes.createType({ name, desc });
    return Result.toAjax(count);
  }

  @Get('')
  async getTypes() {
    const data = await this.houseTypes.getTypes();
    return Result.ok(data);
  }

  @Put('')
  async updateType(@Body() { id, name, desc }: updateTypesDto) {
    const { count } = await this.houseTypes.updateTypes({ id, name, desc });
    return Result.toAjax(count);
  }

  @Delete(':id')
  async deleteTypes(@Param() { id }: deleteTypesDto) {
    const { count } = await this.houseTypes.deleteTypes(id);
    return Result.toAjax(count);
  }
}
